function red () {
  console.log('red');
}
function green () {
  console.log('green');
}
function yellow () {
  console.log('yellow');
}

const task = (time, light) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      if (light === 'red') {
        red()
      } else if (light === 'yellow') {
        yellow()
      } else if (light === 'green') {
        green()
      }
      resolve()
    }, time);
  })
}
const step = () => {
  task(1000, 'red').then(() => {
    return task(1000, 'yellow')
  }).then(() => {
    return task(1000, 'green')
  }).then(() => {
    step()
  })
}
step()
// const task = (timer, light) => {
//   return new Promise((resolve, reject) => {
//     setTimeout(() => {
//       if (light === 'red') {
//         red()
//       } else if (light === 'green') {
//         green()
//       } else if (light === 'yellow') {
//         yellow()
//       }
//       resolve()
//     }, timer);
//   })
// }
// const step = () => {
//   task(3000, 'red')
//     .then(() => task(2000, 'green'))
//     .then(() => task(1000, 'yellow'))
//     .then(step)
// }
// step()
